#1.
def fibo_cache_demo(func):
    cache = {}
    def wrapper(n):
        if n in cache:
            return cache[n]
        else:
            result = func(n)
            cache[n] = result
            return result
    return wrapper


@fibo_cache_demo
def fibo(n):
    print("called")
    if n < 2:
        return n
    return fibo(n-1)+fibo(n-2)

print(fibo(10))
print("使用了装饰器后的Fibonacci过程如下：")
print(fibo(10))
print("-----------------------------------------------")
#2.
#迭代器是一个未知长度的数据流，通过next来获取下一个元素
a= iter([1, 2, 3])
print(type(a))
print("第一次打印：")
print(next(a))
print("第二次打印：")
print(next(a))
print("第三次打印：")
print(next(a))
print("-----------------------------------------------")
#生成器是一个特殊的迭代器，提供了惰性延迟的功能
def foo():
    for i in [1, 2, 3]:
        yield i
        print(f"yield number{i}")
a = foo()
print("第一次打印：")
print(next(a))
print("第二次打印：")
print(next(a))
print("第三次打印：")
print(next(a))


















